<?php
class graph{

	private $game;
	private $back_area = array('width' => 750,'height' => 450);
	private $game_area = array('width' => 400,'height' => 0);
	private $avatar = array('width' => 60,'height' => 60);
	
	function __construct($game){
		$this->game = new game();
		$this->game = $game;
		if ( $game->statut > 3 ){

		}
		$this->draw();
	}
	//accesseurs ???
  	function __get($name) {
    		return $this->$name;
  	}
  	function __set($name,$value) {
    		$this->$name=$value;
  	}
	function draw(){
		switch ($this->game->statut){
		case 0 :
			echo '<div id="back_area" style="width : '.$this->back_area['width'].'px ; height : '.$this->back_area['height'].'px ;">';
			echo "<h2> phase 1 : Nombre de joueurs</h2>\n";
			$this->ask_for_player_number();
			echo "</div>";
			break;
		case 1 :
			$this->game_area['height'] = (( 125 * 2 ) + (( $this->game->nb_player - 2 )* $this->avatar['height']) + (($this->game->nb_player - 3 ) * 50 ));
			$this->back_area['height'] = $this->game_area['height'] + 200;	
			echo '<div id="back_area" style="width : '.$this->back_area['width'].'px ;">'; //height : '.$this->back_area['height'].'px ;">';
			echo "<h2> phase 2 : Nom des joueurs</h2>\n";
			echo '<div id="game_area" style="width : '.$this->game_area['width'].'px ; height : '.$this->game_area['height'].'px ;">';
				$this->ask_for_player_name();			
			echo "</div>";
			echo "</div>";
			break;
		case 2 :
			$this->game_area['height'] = (( 125 * 2 ) + (( $this->game->nb_player - 2 )* $this->avatar['height']) + (($this->game->nb_player - 3 ) * 50 ));
			echo '<div id="back_area" style="width : '.$this->back_area['width'].'px ; ">'; //height : '.$this->back_area['height'].'px ;">';
			echo "<h2> phase 3 : Show players stat</h2>\n";
			echo '<div id="game_area" style="width : '.$this->game_area['width'].'px ; height : '.$this->game_area['height'].'px ;">';
				$this->draw_players_avatar();
			echo 	"<form METHOD='POST' action='index_new.php'>\n		
				<input type=submit value='Commencer la partie'/>\n
				</form>\n";			
			echo "</div>";
			echo "</div>";
			break;
		case 3 :
			$this->game_area['height'] = (( 125 * 2 ) + (( $game->nb_player -2 )* $this->avatar['height']) + (($game->nb_player - 3 ) * 50 ));
			$this->back_area['height'] = $this->back_area['height'] + 200;
			echo "<h2> phase 4 : tire des piges</h2>";
			echo '<div id="back_area" style="width : '.$this->back_area['width'].'px ; ">'; //height : '.$this->back_area['height'].'px ;">';
			echo '<div id="game_area" style="width : '.$this->game_area['width'].'px ; height : '.$this->game_area['height'].'px ;">';	
			echo '<div class="avatar_area" style="width :'.($this->game_area['width'] - 10).'px" >';
			$this->draw_players_avatar();
			echo '</div>';
			break;
		case 4 :
			$this->game_area['height'] = (( 125 * 2 ) + (( $game->nb_player -2 )* $this->avatar['height']) + (($game->nb_player - 3 ) * 50 ));
			$this->back_area['height'] = $this->back_area['height'] + 200;
			echo "<h2> phase 5 : Jeu</h2>";
			echo '<div id="back_area" style="width : '.$this->back_area['width'].'px ; ">'; //height : '.$this->back_area['height'].'px ;">';
			echo '<div id="game_area" style="width : '.$this->game_area['width'].'px ; height : '.$this->game_area['height'].'px ;">';	
			echo '<div class="avatar_area" style="width :'.($this->game_area['width'] - 10).'px ;" >';
			$this->draw_players_avatar();
			echo '</div>';
			break;
		case 5 :
		
			break;
		}
	}
	private function draw_players_avatar(){
		foreach ($this->game->players as $key => $player){
			//$position = $this->get_avatar_position($key);
			echo '<div class="avatar" style="width : '.$this->avatar['width'].'px ; height : '.$this->avatar['height'].'px; " >';//top : '.$position['top'].'px; left="'.$position['left'].'px;
			echo $player->pseudo;
			echo '</div>';
		}
	}
	private function get_avatar_position($id_player){
		$position = array();
		echo $id_player;
		switch($id_player){
			case 0:
				$position['top'] = 0;
				$position['left'] = (( $this->game_area['width'] / 2 ) - $this->avatar['width'] / 2 );
				break;
			default:
				$position['top'] = 0;
				$position['left'] = 0;

		}
		return $position;
	}
	
	private function ask_for_player_number(){
		echo "<form METHOD='POST' id=joueurs action='index_new.php'>\n
				<INPUT type=text name='nbjoueur'/>\n
				<INPUT type=submit />\n 
		      </form>\n";	
	}
	private function ask_for_player_name(){
		echo "<div id='form2'>\n
			<form METHOD='POST' name='get_names' action='index_new.php'>\n
				<table>\n";	
		$i = 0;
		while ($i < $this->game->nb_player){
			echo  "<tr>\n
				<td>Joueur ".($i+1)."</td><td><INPUT type=text class='tb_pseudo' name='name_j".$i."' maxlength=12 /></td>\n
				</tr>";
			$i++;
		}
		echo "</table>\n
				<input type=button value=\"etape suivante\" onClick=\"submit_names();\" />\n
			</form>\n";	
	}
	private function show_players_stat(){
		foreach ($this->game->players as $player){
			print "Joueur".($player->id + 1)." : ".$player->pseudo."<br/>";	
			foreach ($player->stat as $key => $value){
				print $key." => ".$value."<br/>";	
			}
		}
	}
	private function show_players_game_stat(){
		foreach ($this->game->players as $player){
			print "Joueur".($player->id + 1)." : ".$player->pseudo."<br/>";		
			foreach ($player->game_stat as $key => $value){
				print $key." => ".$value."<br/>";	
			}
		}
	}
	private function show_player_stat($player){
		print $player->pseudo;
		foreach ($player->stat as $key => $value){
				print $key." = ".$value."<br/>";	
			}
	}
	private function show_player_game_stat($player){
		print $player->pseudo;
		foreach ($player->game_stat as $key => $value){
				print $key." = ".$value."<br/>";	
			}
	}
}
?>
